﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Serialization;

namespace Common
{
    [XmlRootAttribute("Profil", Namespace = "http://www.sipbop.com", IsNullable = false)]
    public class Profil
    {
        public string Yayasan;
        public string Sekolah;
        public string KetuaYayasan;
        public string KepalaSekolah;
        public string Bendahara;
    }

    public class ProfilManager
    {
        private const string PROFIL_XML = "profil.xml";
        public Profil ProfilSekolah
        {
            get
            {
                if (!File.Exists(Directory.GetCurrentDirectory() + "\\" + PROFIL_XML))
                    return null;
                else
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Profil));
                    FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\" + PROFIL_XML, FileMode.Open);
                    
                    Profil p = (Profil)serializer.Deserialize(fs);
                    fs.Close();
                    return p;
                }
            }
            set
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Profil));
                TextWriter writer = new StreamWriter(Directory.GetCurrentDirectory() + "\\" + PROFIL_XML);
                serializer.Serialize(writer, value);
                writer.Close();
            }
        }
    }
}
